CC=arm-linux-gnueabihf-gcc
#CC=gcc
BIN=myapp
CFLAGS= -lpthread -lm  -Wall -O

ROOT_DIR=$(shell pwd)

-include path.cfg

OBJS_DIR=debug/obj
BIN_DIR=debug/bin
CUR_SOURCE=${wildcard *.c}
CUR_OBJS=${patsubst %.c, %.o, $(CUR_SOURCE)}
SUBDIRS=$(shell ls -l | grep ^d | awk '{if($$9 != "debug") print $$9}')

export CC BIN OBJS_DIR BIN_DIR ROOT_DIR CFLAGS INCLUDES

all:$(SUBDIRS) $(CUR_OBJS) DEBUG

$(SUBDIRS):ECHO
	make -C $@
DEBUG:ECHO
	make -C debug
	
ECHO:
	@echo $(SUBDIRS)
	
$(CUR_OBJS):%.o:%.c
	$(CC) -c $^ -o $(ROOT_DIR)/$(OBJS_DIR)/$@ $(CFLAGS) $(INCLUDES) 
	
clean:
	rm -rf $(OBJS_DIR)/*.o
	rm -rf $(BIN_DIR)/*
